
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>表白墙 - 爱就大胆说出来</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" th:href="@{/res/layui/css/layui.css}">
  <link rel="stylesheet" th:href="@{/res/css/global.css}">
</head>
<body style="margin-top: 65px;">

<div class="fly-header layui-bg-black" th:include="common/header.html :: head"></div>
<br>

<div class="layui-container fly-marginTop">
  <div class="fly-panel" pad20 style="padding-top: 5px;">
    <!--<div class="fly-none">没有权限</div>-->
    <div class="layui-form layui-form-pane">
      <div class="layui-tab layui-tab-brief" lay-filter="user">
        <ul class="layui-tab-title">
          <li class="layui-this">发送信息</li>
        </ul>
        <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
          <div class="layui-tab-item layui-show">
            <form method="post">
              <div class="layui-form-item layui-form-text">
                <div class="layui-input-block">
                  <textarea id="L_content" name="content" required lay-verify="required" placeholder="详细描述" class="layui-textarea fly-editor" style="height: 260px;"></textarea>
                </div>
              </div>
              <div class="layui-form-item">
                <button class="layui-btn" lay-filter="*" lay-submit>立即发送</button>
              </div>
            </form>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<div class="fly-footer" th:include="common/footer.html :: foot"></div>
<script th:src="@{/res/layui/layui.js}"></script>
<script>
  layui.cache.page = 'jie';
  layui.cache.user = {
    username: '游客'
    ,uid: -1
    ,avatar: '../../res/images/avatar/00.jpg'
    ,experience: 83
    ,sex: '男'
  };
  layui.config({
    version: "3.0.0"
    ,base: '../../res/mods/'
  }).extend({
    fly: 'index'
  }).use('fly');

  layui.use(['jquery','form','fly'], function(){
    var form = layui.form;
    var $=layui.jquery;
    var fly=layui.fly;

    form.on('submit(*)', function(data){

      // fly.json('/message/send/', {
      //   uid: [[${userId}]],
      //   message: data.field.content
      // }, function(res){
      //   //我服了，为什么这段就不执行
      //   layer.msg("发送成功123123");
      //   if (res.code === 0){
      //     layer.msg("发送成功");
      //     location.href = '/user/home/'+[[${userId}]];
      //   }else{
      //     layer.msg("服务器繁忙");
      //   }
      // });

      var map={};
      map["uid"]=[[${userId}]];
      map["message"]=data.field.content;
      var dataJson=JSON.stringify(map);

      $.ajax({
        url:"/message/send",
        data:dataJson,
        method:"POST",
        contentType : "application/json;charset=UTF-8",//必须
        dataType:"json",
        success:function(data){
          if (data.code === 0){
            layer.msg("发送成功");
            location.href = data.url;
          }else{
            layer.msg("服务器繁忙");
          }
        },
        error:function(data){
          layer.msg("服务器繁忙，请稍后再试");
        }
      });
      return false;
    });
  });
</script>
</body>
</html>